package com.duruikang.LeaveAPI.dao;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.duruikang.LeaveAPI.entity.Examine;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

import java.util.List;
import java.util.Map;

/**
 * @author szh Drik
 */
public interface ExamineDao extends BaseMapper<Examine> {
    @Select("SELECT " +
            "examine.examine_date, " +
            "(SELECT teacher.teacher_type FROM teacher WHERE examine.teacher_id = teacher.teacher_id )AS teacher_type, " +
            "(SELECT teacher.name FROM teacher WHERE examine.teacher_id=teacher.teacher_id)AS teacher_name, " +
            "(SELECT sort.name FROM sort WHERE sort.id = examine.examine_result)AS examine_result, " +
            "examine.examine_comment  " +
            "FROM examine  " +
            "WHERE examine.leaving_id = #{leavingId} ORDER BY teacher_type;")
    public List<Map<String, String>> getExamineById(@Param("leavingId") String leavingId);

    /**
     * 查询审批历史，6列：请假单id，请假单号，请假理由，请假时间，审批结果，审批时间
     *
     * @param teacherId 教师id
     * @return map list
     */
    @Select("SELECT " +
            "leaving.leaving_id AS leavingId, " +
            "leaving.leaving_code AS leavingCode, " +
            "(SELECT sort.name  FROM `sort` WHERE sort.id = leaving.leaving_reason) AS 'leavingReason', " +
            "leaving.leaving_date AS 'leavingDate', " +
            "(SELECT sort.name  FROM `sort` WHERE sort.id = examine.examine_result) AS 'examineResult', " +
            "examine.examine_date AS 'examineDate' " +
            "from `leaving`,`examine` " +
            "where leaving.leaving_id = examine.leaving_id AND examine.teacher_id = #{teacherId} " +
            "ORDER BY `examine_date` DESC;")
    public List<Map<String, String>> getSimpleHistory(@Param("teacherId") String teacherId);
}
